-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch NullPointerException for onRequestPermissionsResult
#39715
Catch NullPointerException for onRequestPermissionsResult
#39715
Conversation
On Android 13 Devices, we are seeing `NullPointerException`, which should be handled with this
Base commit: bad027c |
Generally catching a NullPointerException means you're masking an underlying error. What object is null? |
Do you have a callstack? |
Here's the CallStack
I am on react native 0.72.4 |
|
mCallbacks.get(requestCode).invoke(grantResults, getPermissionAwareActivity()); | ||
mCallbacks.remove(requestCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead add a null-check here.
mCallbacks.get(requestCode).invoke(grantResults, getPermissionAwareActivity()); | |
mCallbacks.remove(requestCode); | |
Callback callback = mCallbacks.get(requestCode); | |
if (callback != null) { | |
callback.invoke(grantResults, getPermissionAwareActivity()); | |
mCallbacks.remove(requestCode); | |
} else { | |
// Log warning. It's unexpected we're getting a response here we didn't ask for. | |
} |
String message = "Unable to find callback with requestCode:" + requestCode; | ||
FLog.w("PermissionsModule", message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inline message
String message = "Unable to find callback with requestCode:" + requestCode; | |
FLog.w("PermissionsModule", message); | |
FLog.w("PermissionsModule", "Unable to find callback with requestCode:" + requestCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since this is FLog, you can do FLog.w("PermissionsModule", "Unable to find callback with requestCode %d", requestCode)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you updated
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary:
On Android 13 Devices, we are seeing
NullPointerException
, which should be handled with thisChangelog:
[ANDROID] [FIXED] - Handle Crash for onRequestPermissionsResult
Test Plan: